home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / FixMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  5.0 KB  |  229 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        FixMath.h
  3.  
  4.      Contains:    Fixed Math Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1985-1997 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FIXMATH__
  19. #define __FIXMATH__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47.  
  48.  
  49. #define fixed1                ((Fixed) 0x00010000L)
  50. #define fract1                ((Fract) 0x40000000L)
  51. #define positiveInfinity    ((long)  0x7FFFFFFFL)
  52. #define negativeInfinity    ((long)  0x80000000L)
  53. /*
  54.     Previously in ToolUtils.i.  Moved here because it makes more sense.
  55. */
  56. #if !OLDROUTINELOCATIONS
  57. EXTERN_API( Fixed )
  58. FixRatio                        (short                     numer,
  59.                                  short                     denom)                                ONEWORDINLINE(0xA869);
  60.  
  61. EXTERN_API( Fixed )
  62. FixMul                            (Fixed                     a,
  63.                                  Fixed                     b)                                    ONEWORDINLINE(0xA868);
  64.  
  65. EXTERN_API( short )
  66. FixRound                        (Fixed                     x)                                    ONEWORDINLINE(0xA86C);
  67.  
  68. #endif  /*  !OLDROUTINELOCATIONS */
  69.  
  70. EXTERN_API( Fract )
  71. Fix2Frac                        (Fixed                     x)                                    ONEWORDINLINE(0xA841);
  72.  
  73. EXTERN_API( long )
  74. Fix2Long                        (Fixed                     x)                                    ONEWORDINLINE(0xA840);
  75.  
  76. EXTERN_API( Fixed )
  77. Long2Fix                        (long                     x)                                    ONEWORDINLINE(0xA83F);
  78.  
  79. EXTERN_API( Fixed )
  80. Frac2Fix                        (Fract                     x)                                    ONEWORDINLINE(0xA842);
  81.  
  82. EXTERN_API( Fract )
  83. FracMul                            (Fract                     x,
  84.                                  Fract                     y)                                    ONEWORDINLINE(0xA84A);
  85.  
  86. EXTERN_API( Fixed )
  87. FixDiv                            (Fixed                     x,
  88.                                  Fixed                     y)                                    ONEWORDINLINE(0xA84D);
  89.  
  90. EXTERN_API( Fract )
  91. FracDiv                            (Fract                     x,
  92.                                  Fract                     y)                                    ONEWORDINLINE(0xA84B);
  93.  
  94. EXTERN_API( Fract )
  95. FracSqrt                        (Fract                     x)                                    ONEWORDINLINE(0xA849);
  96.  
  97. EXTERN_API( Fract )
  98. FracSin                            (Fixed                     x)                                    ONEWORDINLINE(0xA848);
  99.  
  100. EXTERN_API( Fract )
  101. FracCos                            (Fixed                     x)                                    ONEWORDINLINE(0xA847);
  102.  
  103. EXTERN_API( Fixed )
  104. FixATan2                        (long                     x,
  105.                                  long                     y)                                    ONEWORDINLINE(0xA818);
  106.  
  107. /*
  108.     Frac2X, Fix2X, X2Fix, and X2Frac translate to and from
  109.     the floating point type "extended" (that's what the X is for).
  110.     On the original Mac this was 80-bits and the functions could be
  111.     accessed via A-Traps.  When the 68881 co-processor was added,
  112.     it used 96-bit floating point types, so the A-Traps could not 
  113.     be used.  When PowerPC was added, it used 64-bit floating point
  114.     types, so yet another prototype was added.
  115. */
  116. #if TARGET_CPU_68K
  117. #if TARGET_RT_MAC_68881
  118. EXTERN_API( long double )
  119. Frac2X                            (Fract                     x);
  120.  
  121. EXTERN_API( long double )
  122. Fix2X                            (Fixed                     x);
  123.  
  124. EXTERN_API( Fixed )
  125. X2Fix                            (long double             x);
  126.  
  127. EXTERN_API( Fract )
  128. X2Frac                            (long double             x);
  129.  
  130. #else
  131. EXTERN_API( long double )
  132. Frac2X                            (Fract                     x)                                    ONEWORDINLINE(0xA845);
  133.  
  134. EXTERN_API( long double )
  135. Fix2X                            (Fixed                     x)                                    ONEWORDINLINE(0xA843);
  136.  
  137. EXTERN_API( Fixed )
  138. X2Fix                            (long double             x)                                    ONEWORDINLINE(0xA844);
  139.  
  140. EXTERN_API( Fract )
  141. X2Frac                            (long double             x)                                    ONEWORDINLINE(0xA846);
  142.  
  143. #endif  /* TARGET_RT_MAC_68881 */
  144.  
  145. #else
  146. EXTERN_API( double )
  147. Frac2X                            (Fract                     x);
  148.  
  149. EXTERN_API( double )
  150. Fix2X                            (Fixed                     x);
  151.  
  152. EXTERN_API( Fixed )
  153. X2Fix                            (double                 x);
  154.  
  155. EXTERN_API( Fract )
  156. X2Frac                            (double                 x);
  157.  
  158. #endif  /* TARGET_CPU_68K */
  159.  
  160.  
  161. #if TARGET_CPU_PPC
  162. EXTERN_API_C( short )
  163. WideCompare                        (const wide *            target,
  164.                                  const wide *            source);
  165.  
  166. EXTERN_API_C( WidePtr )
  167. WideAdd                            (wide *                    target,
  168.                                  const wide *            source);
  169.  
  170. EXTERN_API_C( WidePtr )
  171. WideSubtract                    (wide *                    target,
  172.                                  const wide *            source);
  173.  
  174. EXTERN_API_C( WidePtr )
  175. WideNegate                        (wide *                    target);
  176.  
  177. EXTERN_API_C( WidePtr )
  178. WideShift                        (wide *                    target,
  179.                                  long                     shift);
  180.  
  181. EXTERN_API_C( unsigned long )
  182. WideSquareRoot                    (const wide *            source);
  183.  
  184. EXTERN_API_C( WidePtr )
  185. WideMultiply                    (long                     multiplicand,
  186.                                  long                     multiplier,
  187.                                  wide *                    target);
  188.  
  189. /* returns the quotient */
  190. EXTERN_API_C( long )
  191. WideDivide                        (const wide *            dividend,
  192.                                  long                     divisor,
  193.                                  long *                    remainder);
  194.  
  195. /* quotient replaces dividend */
  196. EXTERN_API_C( WidePtr )
  197. WideWideDivide                    (wide *                    dividend,
  198.                                  long                     divisor,
  199.                                  long *                    remainder);
  200.  
  201. EXTERN_API_C( WidePtr )
  202. WideBitShift                    (wide *                    src,
  203.                                  long                     shift);
  204.  
  205. #endif  /* TARGET_CPU_PPC */
  206.  
  207.  
  208.  
  209. #if PRAGMA_STRUCT_ALIGN
  210.     #pragma options align=reset
  211. #elif PRAGMA_STRUCT_PACKPUSH
  212.     #pragma pack(pop)
  213. #elif PRAGMA_STRUCT_PACK
  214.     #pragma pack()
  215. #endif
  216.  
  217. #ifdef PRAGMA_IMPORT_OFF
  218. #pragma import off
  219. #elif PRAGMA_IMPORT
  220. #pragma import reset
  221. #endif
  222.  
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226.  
  227. #endif /* __FIXMATH__ */
  228.  
  229.